\chapter{bsp\+\_\+dwt }
\hypertarget{md__c_1_2_users_2_a_s_u_s_2_desktop_2dm-ctrl_h7-balance-9025test_2bsp_2dwt_2bsp__dwt}{}\label{md__c_1_2_users_2_a_s_u_s_2_desktop_2dm-ctrl_h7-balance-9025test_2bsp_2dwt_2bsp__dwt}\index{bsp\_dwt@{bsp\_dwt}}
\label{md__c_1_2_users_2_a_s_u_s_2_desktop_2dm-ctrl_h7-balance-9025test_2bsp_2dwt_2bsp__dwt_autotoc_md8}%
\Hypertarget{md__c_1_2_users_2_a_s_u_s_2_desktop_2dm-ctrl_h7-balance-9025test_2bsp_2dwt_2bsp__dwt_autotoc_md8}%


DWT是stm32内部的一个"{}隐藏资源"{},他的用途是给下载器提供准确的定时,从而为调试信息加上时间戳.\+并在固定的时间间隔将调试数据发送到你的xxlink上.\hypertarget{md__c_1_2_users_2_a_s_u_s_2_desktop_2dm-ctrl_h7-balance-9025test_2bsp_2dwt_2bsp__dwt_autotoc_md9}{}\doxysection{\texorpdfstring{常用功能}{常用功能}}\label{md__c_1_2_users_2_a_s_u_s_2_desktop_2dm-ctrl_h7-balance-9025test_2bsp_2dwt_2bsp__dwt_autotoc_md9}
\hypertarget{md__c_1_2_users_2_a_s_u_s_2_desktop_2dm-ctrl_h7-balance-9025test_2bsp_2dwt_2bsp__dwt_autotoc_md10}{}\doxysubsection{\texorpdfstring{计算两次进入同一个函数的时间间隔}{计算两次进入同一个函数的时间间隔}}\label{md__c_1_2_users_2_a_s_u_s_2_desktop_2dm-ctrl_h7-balance-9025test_2bsp_2dwt_2bsp__dwt_autotoc_md10}

\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keyword}{static}\ uint32\_t\ cnt;}
\DoxyCodeLine{\textcolor{keywordtype}{float}\ deltaT;}
\DoxyCodeLine{}
\DoxyCodeLine{deltaT=\mbox{\hyperlink{bsp__dwt_8c_af3972f1a5023286afdabf8e79abc5ed7}{DWT\_GetDeltaT}}(\&cnt);}

\end{DoxyCode}
\hypertarget{md__c_1_2_users_2_a_s_u_s_2_desktop_2dm-ctrl_h7-balance-9025test_2bsp_2dwt_2bsp__dwt_autotoc_md11}{}\doxysubsection{\texorpdfstring{计算执行某部分代码的耗时}{计算执行某部分代码的耗时}}\label{md__c_1_2_users_2_a_s_u_s_2_desktop_2dm-ctrl_h7-balance-9025test_2bsp_2dwt_2bsp__dwt_autotoc_md11}

\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keywordtype}{float}\ start,end;}
\DoxyCodeLine{start=DWT\_DetTimeline\_ms();}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{comment}{//\ some\ proc\ to\ go...\ }}
\DoxyCodeLine{\textcolor{keywordflow}{for}(uint8\_t\ i=0;i<10;i++)}
\DoxyCodeLine{\ foo();}
\DoxyCodeLine{}
\DoxyCodeLine{end\ =\ DWT\_DetTimeline\_ms()-\/start;}

\end{DoxyCode}


我们还提供了一个宏用于调试计时\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{preprocessor}{\#define\ TIME\_ELAPSE(dt,\ code)\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{\textcolor{preprocessor}{\ \ \ \ do\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{\textcolor{preprocessor}{\ \ \ \ \{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{\textcolor{preprocessor}{\ \ \ \ \ \ \ \ float\ tstart\ =\ DWT\_GetTimeline\_s();\ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{\textcolor{preprocessor}{\ \ \ \ \ \ \ \ code;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{\textcolor{preprocessor}{\ \ \ \ \ \ \ \ dt\ =\ DWT\_GetTimeline\_s()\ -\/\ tstart;\ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{\textcolor{preprocessor}{\ \ \ \ \ \ \ \ LOGINFO("{}[DWT]\ "{}\ \#dt\ "{}\ =\ \%f\ s\(\backslash\)r\(\backslash\)n"{},\ dt);\ \(\backslash\)}}
\DoxyCodeLine{\textcolor{preprocessor}{\ \ \ \ \}\ while\ (0)}}

\end{DoxyCode}


传入一个float类型的变量,并将你要执行的代码写入第二个参数\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{float}\ my\_func\_dt;}
\DoxyCodeLine{\mbox{\hyperlink{bsp__dwt_8h_a9b46a15916bbafb8610eb121c36dce04}{TIME\_ELAPSE}}(my\_func\_dt,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ Function1(vara);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ Function2(some,\ var);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ Function3(your,param);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ something\ more}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ );}
\DoxyCodeLine{\textcolor{comment}{//\ my\_func\_dt\ can\ be\ used\ for\ other\ purpose\ then;}}

\end{DoxyCode}
 